package com.shop2cn.iapi.member.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.shop2cn.iapi.member.parameter.CollectionMemberInfoBean;
import com.shop2cn.iapi.member.parameter.CreateMemberBean;
import com.shop2cn.iapi.member.parameter.GetMemberBean;
import com.shop2cn.iapi.member.service.GetMemberCall;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.GodMemberService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.utils.TestDataManager;
/**
*查询店铺中的手机号用户
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetMember{
	private static GetMemberBean getmemberBean;
	private static GetMemberCall getmemberCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询店铺中的手机号用户");
	}

	@Before
	public void caseUp() {
		getmemberBean=new GetMemberBean();
		getmemberCall=new GetMemberCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getmemberCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetMember_001() {
		Logger.start(true,"查询店铺中的手机号用户成功");
		try {
			Integer shopId=DGUserCallService.TestWxsqOtherSellerId;
			String mobile=TestDataManager.getPhoneNum();
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			usercreateBean.setShopId(shopId);
			usercreateBean.setMobile(mobile);
			usercreateBean.setUserType(3);
			Integer userId = DGUserCallService.UserCreateCall(usercreateBean);
			UserCreateBean usercreateBean2 = DGUserCallService.initUsercreateBean();
			Integer userId2 = DGUserCallService.UserCreateCall(usercreateBean2);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopId,userId2,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			Integer csid=1;
			GodMemberService.bindMobile(shopId, userId2, mobile,csid);
			
			getmemberBean.setMobile(mobile);
			getmemberBean.setShopId(shopId);
			getmemberCall.setData(getmemberBean);
			getmemberCall.callService();			
			Logger.verifyEquals("200", getmemberCall.getString("code"), "验证code");
			Logger.verifyEquals(1, getmemberCall.getJsonObject().get("data").getAsJsonArray()
					.size(), "验证返回");
			JsonObject data = getmemberCall.getJsonObject().get("data").getAsJsonArray().get(0).getAsJsonObject();
			Logger.verifyEquals(memid, data.get("memberId").getAsString(), "验证memberId");
//Thread:main 2020-06-17 16:12:12.106 返回报文{"code":200,"message":"","data":[{"memberId":"HY20200617008921","nickName":"NickautoTest","realName":null,"mobile":null,"availablePoints":0,"sex":null,"wechatName":null,"collectionMobile":false,"needInvitationCode":false,"csId":0,"bindMobile":false,"dsId":501104002}]}
			Logger.verifyEquals(usercreateBean.getNickname(), data.get("nickName").getAsString(), "验证nickName");
			Logger.verifyEquals(csid.toString(), data.get("csId").getAsString(), "验证csId");
			Logger.verifyEquals(userId.toString(), data.get("dsId").getAsString(), "验证dsId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetMember_002() {
		Logger.start(true,"不输入shopid失败");
		try {
			Integer shopId=DGUserCallService.TestWxsqOtherSellerId;
			String mobile=TestDataManager.getPhoneNum();
			getmemberBean.setMobile(mobile);
//			getmemberBean.setShopId(shopId);
			getmemberCall.setData(getmemberBean);
			getmemberCall.callService();			
			Logger.verifyEquals("400", getmemberCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetMember_003() {
		Logger.start(true,"不输入mobile失败");
		try {
			Integer shopId=DGUserCallService.TestWxsqOtherSellerId;
			String mobile=TestDataManager.getPhoneNum();
//			getmemberBean.setMobile(mobile);
			getmemberBean.setShopId(shopId);
			getmemberCall.setData(getmemberBean);
			getmemberCall.callService();			
			Logger.verifyEquals("400", getmemberCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetMember_004() {
		Logger.start(true,"输入mobile不存在失败");
		try {
			Integer shopId=DGUserCallService.TestWxsqOtherSellerId;
			String mobile=TestDataManager.getPhoneNum();
			getmemberBean.setMobile(mobile);
			getmemberBean.setShopId(shopId);
			getmemberCall.setData(getmemberBean);
			getmemberCall.callService();			
			Logger.verifyEquals("200", getmemberCall.getString("code"), "验证code");
			Logger.verifyEquals(0, getmemberCall.getJsonObject().get("data").getAsJsonArray()
					.size(), "验证无返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetMember_005() {
		Logger.start(true,"根据手机号找到用户会员信息-出现h5和app共有的情况");
		try {
			Integer shopid=DGUserCallService.TestWxsqOtherSellerId;
			String mobile=TestDataManager.getPhoneNum();
			UserCreateBean dusercreateBean = DGUserCallService.initUsercreateBean();
			dusercreateBean.setShopId(shopid);
			dusercreateBean.setMobile(mobile);
			dusercreateBean.setUserType(3);
			Integer duserId = DGUserCallService.UserCreateCall(dusercreateBean);
			
			//2个userid 创建了2个会员 一个h5 一个小程序 使用同一个手机号绑定 在支付查询的时候需要按场景(h5 小程序)返回对应的openid
			UserCreateBean usercreateBean= DGUserCallService.initUsercreateBean();
			int userId=DGUserCallService.UserCreateCall(usercreateBean);
			UserCreateBean usercreateBean2= DGUserCallService.initUsercreateBean();
			int userId2=DGUserCallService.UserCreateCall(usercreateBean2);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			//60.小程序 61.h5
			createMem.setAccessSource(0);
			String mid = GodMemberService.creatememberCall(createMem);
			
			CreateMemberBean createMem2 = GodMemberService.initCreateMemberBean(shopid,userId2,usercreateBean2.getOpenId());
			//60.小程序 61.h5
			createMem2.setAccessSource(1);
			String mid2 = GodMemberService.creatememberCall(createMem2);
			
			GodMemberService.bindMobile(shopid, userId, mobile);
			GodMemberService.bindMobile(shopid, userId2, mobile);
			getmemberBean.setShopId(shopid);
			getmemberBean.setMobile(mobile);
			getmemberCall.setData(getmemberBean);
			getmemberCall.callService();			
			Logger.verifyEquals("200", getmemberCall.getString("code"), "验证code");
			Logger.verifyEquals(2, getmemberCall.getJsonObject().get("data").getAsJsonArray()
					.size(), "验证返回");
			JsonObject data = getmemberCall.getJsonObject().get("data").getAsJsonArray().get(0).getAsJsonObject();
			Logger.verifyEquals(mid, data.get("memberId").getAsString(), "验证memberId");
			JsonObject data2 = getmemberCall.getJsonObject().get("data").getAsJsonArray().get(1).getAsJsonObject();
			Logger.verifyEquals(mid2, data2.get("memberId").getAsString(), "验证memberId");
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetMember_006() {
		Logger.start(true,"查询店铺中的手机号用户成功-收集信息数据正确");
		try {
			Integer shopId=DGUserCallService.TestWxsqOtherSellerId;
			String mobile=TestDataManager.getPhoneNum();
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			usercreateBean.setShopId(shopId);
			usercreateBean.setMobile(mobile);
			usercreateBean.setUserType(3);
			Integer userId = DGUserCallService.UserCreateCall(usercreateBean);
			UserCreateBean usercreateBean2 = DGUserCallService.initUsercreateBean();
			Integer userId2 = DGUserCallService.UserCreateCall(usercreateBean2);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopId,userId2,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			
			CollectionMemberInfoBean collectionmemberinfoBean=new CollectionMemberInfoBean();
			collectionmemberinfoBean.setUserId(userId2);
			collectionmemberinfoBean.setRealName("rname");
			collectionmemberinfoBean.setSex("男");
			collectionmemberinfoBean.setShopId(shopId);
			collectionmemberinfoBean.setWechatName("wxname");
			GodMemberService.collectionmemberinfoCall(collectionmemberinfoBean);
			
			Integer csid=1;
			GodMemberService.bindMobile(shopId, userId2, mobile,csid);
			
			getmemberBean.setMobile(mobile);
			getmemberBean.setShopId(shopId);
			getmemberCall.setData(getmemberBean);
			getmemberCall.callService();			
			Logger.verifyEquals("200", getmemberCall.getString("code"), "验证code");
			Logger.verifyEquals(1, getmemberCall.getJsonObject().get("data").getAsJsonArray()
					.size(), "验证返回");
			JsonObject data = getmemberCall.getJsonObject().get("data").getAsJsonArray().get(0).getAsJsonObject();
			Logger.verifyEquals(memid, data.get("memberId").getAsString(), "验证memberId");
//Thread:main 2020-06-17 16:12:12.106 返回报文{"code":200,"message":"","data":[{"memberId":"HY20200617008921","nickName":"NickautoTest","realName":null,"mobile":null,"availablePoints":0,"sex":null,"wechatName":null,"collectionMobile":false,"needInvitationCode":false,"csId":0,"bindMobile":false,"dsId":501104002}]}
			Logger.verifyEquals(usercreateBean.getNickname(), data.get("nickName").getAsString(), "验证nickName");
			Logger.verifyEquals(csid.toString(), data.get("csId").getAsString(), "验证csId");
			Logger.verifyEquals(userId.toString(), data.get("dsId").getAsString(), "验证dsId");
			Logger.verifyEquals(collectionmemberinfoBean.getSex(), data.get("sex").getAsString(), "验证sex");
			Logger.verifyEquals(collectionmemberinfoBean.getRealName(), data.get("realName").getAsString(), "验证realName");
			Logger.verifyEquals(collectionmemberinfoBean.getWechatName(), data.get("wechatName").getAsString(), "验证wechatName");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}